from rest_framework import serializers
from .models import Project, Environment


class ProjectSerializer(serializers.ModelSerializer):
    class Meta:
        model = Project
        fields = ['id', 'name', 'intro', 'url', 'status', 'pytest_config', 'created_time', 'updated_time']
        read_only_fields = ['created_time', 'updated_time']


class EnvironmentSerializer(serializers.ModelSerializer):
    project_name = serializers.CharField(source='project.name', read_only=True)
    
    class Meta:
        model = Environment
        fields = ['id', 'name', 'project', 'project_name', 'base_url', 'variables', 'headers', 'created_time', 'updated_time']
        read_only_fields = ['created_time', 'updated_time', 'project_name'] 